package com.henu.engineer.service.teacher

import com.henu.engineer.dao.entity.teacher.CourseGroup
import com.henu.engineer.dao.mapper.cultivatingproject.RequirementIndicatorXmlMapper
import com.henu.engineer.dao.mapper.teacher.CourseGroupMemberXmlMapper
import com.henu.engineer.dao.mapper.teacher.CourseGroupXmlMapper
import com.henu.engineer.service.LoginService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.ArrayList

/**
 *
 * @author noexcept
 * @since 2021/8/11 23:45
 */
@Service
class CourseGroupService {

    @Autowired
    lateinit var courseGroupXmlMapper: CourseGroupXmlMapper

    @Autowired
    lateinit var loginService: LoginService

    @Autowired
    lateinit var courseGroupMemberXmlMapper: CourseGroupMemberXmlMapper

    @Autowired
    lateinit var requirementXmlMapper: RequirementIndicatorXmlMapper

    /**
     * 返回当某老师的所有课程组信息
     */
    fun getCourseGroup(teacherId: String): List<CourseGroup> {
        var courseGroupIds = courseGroupMemberXmlMapper.selectGroupIdsByTeacherId(teacherId) as ArrayList<String>
        if (courseGroupIds.size == 0)
            return ArrayList<CourseGroup>()
        return courseGroupXmlMapper.selectByCourseGroupIds(courseGroupIds)
    }


    /**
     * 返回某课程组的所有教师的名字和id
     */
    fun getCourseGroupMember(courseGroupId: String): List<Pair<String, String>> {
        return courseGroupMemberXmlMapper.selectByCourseGroupId(courseGroupId)
            .map { Pair(it.teacherId, it.teacherName) }
    }


    /**
     * 返回某一毕业要求对应的所有指标点    这个不确定写的对不  是不是还要返回所有指标点对应的毕业要求
     */
    fun getAllRequirementIndicatorByRequirementId(requirementId:Int)
            =requirementXmlMapper.selectIndicatorByRequirementId(requirementId)

    /**
     * 课程组的创建
     */

    fun courseGroupCreate(name: String,courseId:String,teacherId:Int,createTime: LocalDate)=
        courseGroupXmlMapper.courseGroupCreate(name,courseId,teacherId,createTime)

}